/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package grex.fitnessfunctions.Regression;

import grex.Prediction;
import grex.fitnessfunctions.FitnessFunction;
import java.io.Serializable;

/**
 *
 * @author RIK
 */
public class MUAPE_Fitness extends FitnessFunction implements Serializable{

    public MUAPE_Fitness() {
        super(FitnessFunction.MUAPE);
    }
   public MUAPE_Fitness(String name,Double instanceKey) {
        super(name,instanceKey);
    }

    @Override
    protected double calcPredictionError(Prediction prediction, double targetValue) {
        double p = prediction.getPrediction();
        double t = targetValue;
        if(p+t==0)
            return 0;    
       double error = Math.abs((p-t)/((p+t)/2));       
       return Math.min(error, 10);
    }
}
